/*******************************************************************************
File: 5_child_protection
Project: CPKIN
Purpose: This .do file cleans and analyzes data on child protection outcomes
Author: Akshay Dixit
Date Created: Feb 11, 2019
Date modified: June 30, 2020
********************************************************************************/

clear all
set more off

***THIS IS THE INPUT THAT MUST BE CHANGED SPECIFIC TO THE USER***
*gl identity ""
*gl user "" 

********************************************************************************

***Creating Global File Paths***'
gl data "$user/data"
gl dof "$user/do files"
gl analysis "$user/analysis"

********************************************************************************

u "$data/endline_adult_chief_child_data.dta", clear


* Keeping child survey - these outcomes are based entirely on the child survey
keep if type_survey == "child"

* Stratification variable - Chiefdom
gl chiefdom = "bagruwa_chief barri_chief bumpeh_chief fakunya_chief gallinas_perri_chief kaiyamba_chief kamarjei_chief kori_chief kowa_chief kpaka_chief malin_chief sowa_chief"

* Control variables
gl controls = "wealth_index female age attend_school fp_visit vil_pop"

* Outcome variables

desc hurt_by_chd hurt_by_adult hurt_by_oth_chdrn //Abuse
desc farm_wrk log_frwood heavy_load other_heavy_wrk other_heavywrk1 oth_work_often1 other_heavywrk2 other_heavywrk3 oth_Hev_work2 //Heavy work

foreach var in hurt_by_chd hurt_by_adult hurt_by_oth_chdrn farm_wrk log_frwood heavy_load other_heavy_wrk other_heavywrk1 ///
oth_work_often1 other_heavywrk2 other_heavywrk3 oth_Hev_work2 {
	di "`var'"
	tab `var'
}

g any_farm_work = (farm_wrk == 1 | farm_wrk == 2 | farm_wrk == 3)
replace any_farm_work = . if farm_wrk == .

g any_log_firewood = (log_frwood == 1 | log_frwood == 2 | log_frwood == 3)
replace any_log_firewood = . if log_frwood == .

g any_heavy_load = (heavy_load == 1 | heavy_load == 2 | heavy_load == 3)
replace any_heavy_load = . if heavy_load == .

g other_heavy_work = (other_heavy_wrk == "yes" | other_heavywrk2 == "yes")
replace other_heavy_work = . if other_heavy_wrk == ""

ren hurt_by_chd child_abuse
	
* Label variables

lab var child_abuse "Whether there have been incidents of child abuse in village"
lab var any_farm_work "Whether child did hard work on the farm"
lab var any_log_firewood "Whether logged for firewood"
lab var any_heavy_load "Whether carried heavy loads"
lab var other_heavy_work "Whether child did any other heavy work"

lab var treatment "Treatment"
lab var wealth_index "Wealth index" 
lab var female "Female"
lab var age "Age"
lab var attend_school "Ever attended school" 
lab var fp_visit "Village visited by UNICEF monitoring team"
lab var vil_pop "Village population"
lab var chief "Respondent: Chief"
lab var sms_received "CPKIN SMS received"

********************************************************************************

***ITT analysis***

cd "$analysis"

cap erase "ITT_child_protection.xls"

local outcomes child_abuse any_farm_work any_log_firewood any_heavy_load other_heavy_work
foreach var of local outcomes {
		
	di "`var'" 
	
	qui sum `var' if treatment == 0
	local control_mean = (r(mean))
	local rounded = round(`control_mean', 0.01)
	
	qui reg `var' treatment $chiefdom $controls, vce(cluster village_id1)
	
	local p = 2 * (1-normal(abs(_b[treatment]/_se[treatment])))
	local p_round = round(`p', 0.001)
	
	outreg2 using "ITT_child_protection.xls", append label keep(treatment wealth_index female age attend_school fp_visit vil_pop) ///
	addtext(Naive p-value, "`p_round'", Control group mean, "`rounded'") ///
	addnote("Standard errors clustered at the village-level. Specifications include binary variables for randomization strata.")
	
}

cap erase "ITT_child_protection.txt"

********************************************************************************

***TOT analysis with sms_received as instrument***

cap erase "TOT_child_protection.xls"

local outcomes child_abuse any_farm_work any_log_firewood any_heavy_load other_heavy_work
foreach var of local outcomes {
		
	di "`var'"
	
	qui sum `var' if treatment == 0
	local control_mean = (r(mean))
	local rounded = round(`control_mean', 0.01)
	
	qui ivregress 2sls `var' $chiefdom $controls (sms_received = treatment), vce(cluster village_id1)
	
	local p = 2 * (1-normal(abs(_b[sms_received]/_se[sms_received])))
	local p_round = round(`p', 0.001)
	
	outreg2 using "TOT_child_protection.xls", append label keep(sms_received wealth_index female age attend_school fp_visit vil_pop) ///
	addtext(Naive p-value, "`p_round'", Control group mean, "`rounded'") ///
	addnote("Standard errors clustered at the village-level. Specifications include binary variables for randomization strata.") 	
	
}

cap erase "TOT_child_protection.txt"

********************************************************************************

clear


